<style>
	.headerImg {
		height: 20px;
		width: 20px;
		border-radius: 16rpx;
	}
</style>
<template>
	<div id="app">
		<div :style="{'height':height+'px'}" v-loading="loading1">
			<el-row style="height: 100%;">
				<el-col :span="6" style="padding:20px;height: 100%;background: #fff;border-radius: 16px;">
					<div
						style="display: flex;align-items: center;text-align: left;font-weight: bold;font-size: 20px;color: #333;padding-bottom: 20px;border-bottom: 1px solid#F6F6F6;">
						<img v-if="leftData.title=='环境影响评估'" src="@/assets/huanbao/icon1.png" class="headerImg" />
						<img v-if="leftData.title=='排污许可证'" src="@/assets/huanbao/icon2.png" class="headerImg" />
						<img v-if="leftData.title=='排污许可执行报告'" src="@/assets/huanbao/icon3.png" class="headerImg" />
						<img v-if="leftData.title=='危险废物档案'" src="@/assets/huanbao/icon4.png" class="headerImg" />
						<img v-if="leftData.title=='一般工业固废档案'" src="@/assets/huanbao/icon5.png" class="headerImg" />
						<img v-if="leftData.title=='废水管理档案'" src="@/assets/huanbao/icon6.png" class="headerImg" />
						<img v-if="leftData.title=='废气管理档案'" src="@/assets/huanbao/icon7.png" class="headerImg" />
						<div style="margin-left: 10px;">
							{{leftData.title}}
						</div>
					</div>

					<div v-for="(item,index) in leftData.list" @click="selectItem(item)" class="leftItemClass"
						@contextmenu.prevent.stop="rowContextmenu($event,item)">
						<div :class="[leftSelectItem.id == item.id?'selectedClass':'']">{{item.title}}</div>
						<!-- <div style="color: #F56C6C;" @click="uploadInfo(item)">上传</div> -->
						<img src="@/assets/fileCommon.png" style="width: 20px;height: 20px;"
							v-if="item.status == 'EFFECTIVE'" />
						<img src="@/assets/fileEmpty.png" style="width: 20px;height: 20px;"
							v-else-if="item.status == 'NOT_SUBMIT'" />
						<img src="@/assets/fileWarning.png" style="width: 20px;height: 20px;"
							v-else-if="item.status == 'UNQUALIFIED'" />
						<img src="@/assets/sIcon42.png" style="width: 20px;height: 20px;"
							v-else-if="item.status == 'NOT_INVOLVE'" />
					</div>
				</el-col>

				<el-col :span="1" style="padding:20px;height: 100%;">
				</el-col>

				<el-col :span="17" :style="{'height':height+'px'}"
					style="height: 100%;overflow-y: auto;padding: 20px;background: #fff;border-radius: 16px;">
					<pdfView v-if="leftSelectItem.categoryType == 'COMMON'" :leftSelectItem="leftSelectItem"
						ref="pdfView" @uploadInfo="uploadInfo" @closeDia="closeDia"
						@saveBeizhu="getDocumentCategoryMainModeById" />


					<wasteWaterSurvey v-if="leftSelectItem.categoryType =='WATER_SELF_SURVEY'" />
					<wasteWaterOrder v-else-if="leftSelectItem.categoryType =='WATER_STANDING_BOOK'" />
					<wasteGasSurvey v-else-if="leftSelectItem.categoryType =='GAS_SELF_SURVEY'" />
					<wasteGasOrder v-else-if="leftSelectItem.categoryType =='GAS_STANDING_BOOK'" />
					<wasteOrder v-else-if="leftSelectItem.categoryType =='HW_STANDING_BOOK'" />
					<wasteSelfExamineEntDetail v-else-if="leftSelectItem.categoryType =='HW_NORMALIZATION'" />
					<wasteHwOrder v-else-if="leftSelectItem.categoryType =='SW_STANDING_BOOK'" />
					<orderView
						v-if="leftSelectItem.categoryType == 'DANGER_WASTE_ORDER' ||  leftSelectItem.categoryType == 'COMMON_WASTE_ORDER'"
						:leftSelectItem="leftSelectItem" ref="orderView" @uploadInfo="uploadInfo" @closeDia="closeDia"
						@saveBeizhu="getDocumentCategoryMainModeById">
					</orderView>

					<ldView v-if="leftSelectItem.categoryType == 'DRAFT'" :leftSelectItem="leftSelectItem" ref="ldView"
						@uploadInfo="uploadInfo" @closeDia="closeDia" @saveBeizhu="getDocumentCategoryMainModeById" />
				</el-col>
			</el-row>
		</div>

		<el-dialog v-if="visible1" :visible.sync="visible1" width="800px" :title="'合同上传'" @close="closeDia">
			<uploadHtZz ref="uploadHtZz" :selectItem="leftSelectItem" @cancle="closeDia"
				@success="closeDia(),loadOrderView()" :optionType="optionType"></uploadHtZz>
		</el-dialog>

		<el-dialog v-if="visible2" :visible.sync="visible2" width="800px" :title="'文件上传'" @close="closeDia" top="50px">
			<uploadFile ref="uploadFile" :selectItem="leftSelectItem" @success="closeDia(),loadPdfView()"
				@cancle="closeDia" :optionType="optionType">
			</uploadFile>
		</el-dialog>

		<el-dialog v-if="visible3" :visible.sync="visible3" width="800px" :title="'转移联单上传'" @close="closeDia">
			<uploadZyLd ref="uploadZyLd" :selectItem="leftSelectItem" @cancle="closeDia"
				@success="closeDia(),loadldView()" :optionType="optionType"></uploadZyLd>
		</el-dialog>

		<contextMenu ref="contextbutton" @saveInvolve="getDocumentCategoryMainModeById"></contextMenu>
	</div>
</template>

<script>
	import pdf from 'vue-pdf'
	import uploadHtZz from '@/components/upload/uploadHtZz'
	import uploadFile from '@/components/upload/uploadFile'
	import uploadZyLd from '@/components/upload/uploadZyLd'

	import pdfView from '@/components/view/pdfView'
	import ldView from '@/components/view/ldView'
	import orderView from '@/components/view/orderView'
	import wasteWaterOrder from '@/components/wasteWater/order'
	import wasteWaterSurvey from '@/components/wasteWater/survey'
	import wasteGasOrder from '@/components/wasteGas/order'
	import wasteGasSurvey from '@/components/wasteGas/survey'
	import wasteOrder from '@/components/waste/order'
	import wasteSelfExamineEntDetail from '@/components/waste/selfExamineEntDetail'
	import wasteHwOrder from '@/components/wasteHw/order'
	import contextMenu from '@/components/contextMenu'

	let that

	export default {
		name: 'padManage',
		components: {
			pdf,
			uploadHtZz,
			uploadFile,
			uploadZyLd,
			pdfView,
			ldView,
			orderView,
			wasteWaterOrder,
			wasteWaterSurvey,
			wasteGasOrder,
			wasteGasSurvey,
			wasteOrder,
			wasteSelfExamineEntDetail,
			wasteHwOrder,
			contextMenu
		},
		data() {
			return {
				APPKEY: '5da5441f62e48aedc7a3853ffc75c2db',
				PRODID: 'gf',
				UPLOAD_ACTION: '/upload',
				VIEW_ACTION: '/view',
				REMOVE_ACTION: '/remove',
				IMGURL: 'https://www.weifeibangbang.com/wfbb-webupload/service/sys/file/upload',
				fileViewUrl: 'https://www.weifeibangbang.com/wfbb-webupload/service/sys/file/upload/view?appKey=5da5441f62e48aedc7a3853ffc75c2db&prodID=gf&fileID=',

				optionType: "add",

				loading1: false,
				visible1: false,
				visible2: false,
				visible3: false,

				height: window.screen.height - 260,
				leftData: {},
				leftSelectItem: '',
				params: {
					categoryMainId: '',
					ticketId: '',
					itemId: ''
				},

			}
		},
		created: function() {},
		mounted: function() {
			that = this

			that.params.categoryMainId = that.getQueryString("categoryMainId") || ''
			that.params.ticketId = that.$store.state.token
			that.params.itemId = that.getQueryString("itemId")
			that.getDocumentCategoryMainModeById()
		},
		methods: {

			rowContextmenu($event, item) {
				that.selectItem(item)
				that.$refs.contextbutton.init($event, item)
			},


			loadldView() {
				that.getDocumentCategoryMainModeById()
				that.$refs.ldView.pageDocumentEntCategoryDraft()
			},

			loadOrderView() {
				that.getDocumentCategoryMainModeById()
				that.$refs.orderView.getDocumentEntCategoryOrderListByEntId()
			},

			loadPdfView() {
				that.getDocumentCategoryMainModeById()
				that.$refs.pdfView.getEffectiveDocumentRecordByCustomerId()
			},

			closeDia() {
				that.visible1 = false
				that.visible2 = false
				that.visible3 = false
				that.visible4 = false
				if (that.$refs.uploadHtZz) that.$refs.uploadHtZz.removeFile()
				if (that.$refs.uploadFile) that.$refs.uploadFile.removeFile()
				if (that.$refs.uploadZyLd) that.$refs.uploadZyLd.removeFile()
			},

			selectItem(item) {
				that.leftSelectItem = ''
				setTimeout(function() {
					that.leftSelectItem = item
				}, 100)

			},

			//上传点击
			uploadInfo(optionType) {
				that.optionType = optionType
				//console.log(that.leftSelectItem.categoryType)
				if (that.leftSelectItem.categoryType == 'DANGER_WASTE_ORDER' || that.leftSelectItem.categoryType ==
					'COMMON_WASTE_ORDER') {
					that.visible1 = true
				} else if (that.leftSelectItem.categoryType == 'COMMON') {
					that.visible2 = true
				} else if (that.leftSelectItem.categoryType == 'DRAFT') {
					that.visible3 = true
				}
			},

			//获取显示菜单
			getDocumentCategoryMainModeById() {
				that.loading1 = true
				that.ajax({
					url: '/document/getDocumentCategoryMainModeById?ticketId=' + that.params.ticketId,
					data: JSON.stringify({
						categoryMainId: that.params.categoryMainId,
					}),
					contentType: 'application/json',
					dataType: 'json',
					method: 'POST',
					success: function(result) {
						if (result.status == 1) {
							that.leftData = result.data
							if (that.leftSelectItem) {
								for (let item of that.leftData.list) {
									if (item.id == that.leftSelectItem) {
										item.isSelected = true
										that.leftSelectItem = item
									}
								}
							} else {
								for (let item of that.leftData.list) {
									if (item.id == that.params.itemId) {
										item.isSelected = true
										that.leftSelectItem = item
									}
								}
							}
						}
						that.loading1 = false
					}
				});
			},

		}
	}
</script>

<style>
	body {
		margin: unset;
	}

	.selectedClass {
		font-weight: bold;
		color: #3A3EF4;
	}

	.leftItemClass {
		text-align: center;
		line-height: 40px;
		cursor: pointer;
		display: flex;
		justify-content: space-between;
		align-items: center;
		color: #999;
	}

	.rightButton {
		cursor: pointer;
		padding: 10px 20px;
		text-align: center;
	}
</style>